package com.miukoo.aikao.core.types;

import com.miukoo.aikao.core.dtos.QuestionDetailDto;
import com.miukoo.aikao.core.enums.QuestionType;
import com.miukoo.aikao.core.pojos.QuestionChooseDto;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @Author miukoo<miukoo@126.com>
 * @Date 2020/11/25  
 * @Version 1.0
 */
@Component
public class TypeInterfaceManager implements TypeInterface {

    @Autowired
    @Qualifier("radioType")
    TypeInterface radioType;

    @Autowired
    @Qualifier("checkBoxType")
    TypeInterface checkBoxType;

    @Autowired
    @Qualifier("judgeType")
    TypeInterface judgeType;

    @Autowired
    @Qualifier("qaType")
    TypeInterface qaType;

    @Autowired
    @Qualifier("codingType")
    TypeInterface codingType;

    @Override
    public void saveCkeck(QuestionDetailDto dto) {
        getTypeInterface(dto).saveCkeck(dto);
    }

    @Override
    public List<QuestionChooseDto> chooseQuestion(Long repoId, Short type, Short level, Short size, Short answerCount, Short score) {
        return getTypeInterface(type).chooseQuestion(repoId,type,level,size,answerCount,score);
    }

    /**
     * 查找问题的类型
     * @param type
     * @return
     */
    private TypeInterface getTypeInterface(Short type){
        if (type.equals(QuestionType.RADIO.shortValue())){
            return radioType;
        }else if (type.equals(QuestionType.MULTI.shortValue())){
            return checkBoxType;
        }else if (type.equals(QuestionType.JUDGE.shortValue())){
            return judgeType;
        }else if (type.equals(QuestionType.QA.shortValue())){
            return qaType;
        }else if (type.equals(QuestionType.CODING.shortValue())){
            return codingType;
        }
        return null;
    }

    /**
     * 查找问题的类型
     * @param dto
     * @return
     */
    private TypeInterface getTypeInterface(QuestionDetailDto dto){
        return getTypeInterface(dto.getType());
    }
}
